/*
Copyright 2007 Julian Asamer

This file is part of Fractalicious.

    Fractalicious is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Fractalicious is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Fractalicious.  If not, see <http://www.gnu.org/licenses/>.
*/

#import <Foundation/Foundation.h>
#import <CoreFoundation/CoreFoundation.h>
#import "Spiral.h"
#import "Vector.h" //The place where Line2D and Transformer2D are (amongst others) defined.
#import "Dragable.h" //The place where DragablePoint is defined.

@implementation Spiral

//The coordinates
//Just use the coordinates where you want your fractal to be shown initially on the sceen.

-(id) init {
	[super init];
	p = [[DragablePoint alloc] initWithx: 320.0f y: 330.0f];//We only create a dragablePoint here...
	[p addMaximumDistance: 320 fromPoint: [[Point2D alloc] initWithx: 10 y: 330]]; //Prevent user from doing harm... ^^
	[p setDelegate: self]; // and set self to the delegate.
	return self;
}

//Those are the methods which are called by our DragablePoint.
//We could handle some other things, but we just want to recalculate.
-(void) pointChanged {
	[delegate startRecalculation: 1]; //The "1" means fast recalculation (low res).
}
-(void) pointMouseUp {
	[delegate startRecalculation: 0]; //The "0" means full recalculation (high res).
}

//For some reason a simple NSArray didn't work in my case. This is probably subject to change.
-(NSMutableArray *)getStartLines {
	NSMutableArray* lines = [[NSMutableArray alloc] initWithCapacity: 1];
	[lines addObject: 
	//We just create a line with the initial coordinates on the screen.
		[[Line2D alloc] initWithpx: 10.0f py: 10.0f qx: 10.0f qy: 330.0f]
	];
	return lines;
}


//A transformer is kind of a geometric proportion.
//p1 and q1 define the first recursion (rec1) and p2 and q2 define the second recursion (rec2).
//The transformer is a mathematical construct which allows the programm to solve 
//something you can imagine as rec1 : rec2 = rec2 : rec3. rec3 is, of course, unknown at first.
//This way all the following recursions are calculted.
//
//More simply, it means that you have to define the first (p1, q1) and the second 
//(p2, q2) Level to calculate the fractal.
//q2 is in our case simply the DragablePoint - DragablePoint is a subclass of Point2D.
//
//You can also create a transformer using two lines - initWithLine: andLine: .
-(NSMutableArray *)getTransformers {
	NSMutableArray* tf = [[NSMutableArray alloc] initWithCapacity: 1];

	[tf addObject: [[Transformer2D alloc] initWithp1: 
		[[[Point2D alloc] initWithx: 10.0f y: 10.0f] autorelease]
		q1: [[[Point2D alloc] initWithx: 10.0f y: 330.0f] autorelease]
		p2: [[[Point2D alloc] initWithx: 10.0f y: 330.0f] autorelease]
		q2: p] 
	];
	
	return tf;
}

//This method returns the used Dragables, so they can be drawen by FView.
-(NSMutableArray *)getDragables {
	NSMutableArray* dg = [[NSMutableArray alloc] initWithCapacity: 1];
	[dg addObject: p];
	return dg;
}


//We had that...
-(id) delegate {
	return delegate;
}
-(void) setDelegate:(id) d {
	delegate = d;
}


@end